package com.gisquest.cloud.common.utils;

import com.gisquest.cloud.entity.page.Pagination;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;

/**
 * @Author guowei
 * @Date 2020/6/18 8:29
 * @Description:获取到的数据分页
 **/
public class PaginationUtils {

  public static <T> Pagination<T> convertPage(PageInfo<T> page) {
    Pagination spage = new Pagination();
    try {
      spage.setItems(page.getList());
      spage.setPageNum(page.getPageNum());
      spage.setPages(page.getPages());
      spage.setPageSize(page.getPageSize());
      spage.setTotal(page.getTotal());
      return spage;
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }


  public static <T> Pagination<T> convertPage(Page<T> page) {
    Pagination spage = new Pagination();
    try {
      spage.setItems(page.getResult());
      spage.setPageNum(page.getPageNum());
      spage.setPages(page.getPages());
      spage.setPageSize(page.getPageSize());
      spage.setTotal(page.getTotal());
      return spage;
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
}
